<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="apple-mobile-web-app-status-bar-style" content="black" />
		<meta name="format-detection" content="telephone=no" />
		<title>微信支付测试</title>
		<link rel="stylesheet" href="//cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css">
		<script src="http://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>

	</head>

	<body style="margin-left: 5px; margin-right: 5px">
		<div style="margin-top: 15px">
			<div class="panel panel-success">
				<div class="panel-heading">
					<h3 class="panel-title">升级日志 （肖得明）</h3>
				</div>
				<div class="panel-body">
					<p>微信安全支付目录:<code>http://xxxx.com/weixin/pay/</code></p>
					<p>1. 当前页面唤醒支付</p>
					<p>2. Ajax唤醒支付</p>
				</div>
			</div>
			<a href="JavaScript:;" type="button" class="btn btn-success btn-lg btn-block testpay">当前页面唤醒支付</a>
			<a href="JavaScript:;" type="button" class="btn btn-lg btn-block btn-primary ajax_getPay">Ajax请求支付参数</a>

		</div>
		<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.1.0.js"></script>
		<script src="/weixin/jssdk"></script>
	</body>
	<script>
		$(function() {
			//演示1 当前页面支付
			$(".testpay").click(function() {
				WeixinJSBridge.invoke('getBrandWCPayRequest', {
					"appId": '${appId!}', //公众号名称，由商户传入
					"timeStamp": '${timeStamp!}', //时间戳，自 1970 年以来的秒数
					"nonceStr": '${nonceStr!}', //随机串
					"package": '${package!}',
					"signType": '${signType!}', //微信签名方式:
					"paySign": '${paySign!}' //微信签名
				}, function(res) {
					if(res.err_msg == "get_brand_wcpay_request:ok") {
						alert("订单支付成功！");
						//window.location.replace("/wx/group/detail/${order.group_order_id!}");
					} else {
						// 支付失败
						alert("1支付失败，请重试！" + res.err_msg);
					}

				});
			})

			//ajax  get请求支付
			$(".ajax_getPay").click(function() {
				$.getJSON("/weixin/pay/demo/ajax_get", function(d) {
					if(d.state) {
						call_weixin_pay(d.data);
					}
				});
			})
		})

		function call_weixin_pay(obj) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', {
				"appId": obj.appId, //公众号名称，由商户传入
				"timeStamp": obj.timeStamp, //时间戳，自 1970 年以来的秒数
				"nonceStr": obj.nonceStr, //随机串
				"package": obj.package,
				"signType": obj.signType, //微信签名方式:
				"paySign": obj.paySign //微信签名
			}, function(res) {
				if(res.err_msg == "get_brand_wcpay_request:ok") {
					alert("订单支付成功！");
				} else {
					// 支付失败
					alert("1支付失败，请重试！" + res.err_msg);
				}

			});
		}
	</script>

</html>